package com.li.my_tiny_spring.util.io;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

import com.li.my_tiny_spring.exception.impl.MyIllegalStateException;

public class UrlResource implements Resource {

	private final URL url;

	public UrlResource(URL url) {
		this.url = url;
	}

	@Override
	public InputStream getInputStream() {
		try {
			URLConnection urlConnection;
			urlConnection = url.openConnection();
			urlConnection.connect();
			return urlConnection.getInputStream();
		} catch (IOException e) {
			throw new MyIllegalStateException(e);
		}
	}
}
